export const BASE_URL = "https://czz.mapp.yunchuan.info"

// 统一POST请求
export const postApi = (url, data={})=>{
	let token = uni.getStorageSync("token") || ""
	return new Promise((resolve, reject)=>{
		uni.request({
			url:BASE_URL + url,
			method:"POST",
			timeout:10000,
			header:{
				token:token
			},
			data,
			success(res) {
				// 登录过期处理
				if(res.code === -1 || res.code === 0) {
					uni.navigateTo({
						url:"/pages/login/login"
					})
				}else{
					resolve(res.data)
				}
			},
			fail(err) {
				uni.hideLoading()
				reject(err)
			}
		})
	})
}

// 统一get请求
export const getApi = (url)=>{
	let token = uni.getStorageSync("token") || ""
	return new Promise((resolve, reject)=>{
		uni.request({
			url:BASE_URL + url,
			method:"GET",
			timeout:10000,
			header:{
				token:token
			},
			success(res) {
				// 登录过期处理
				if(res.code === -1 || res.code === 0) {
					uni.navigateTo({
						url:"/pages/login/login"
					})
				}else{
					resolve(res.data)
				}
			},
			fail(err) {
				console.log(err)
				reject(err)
			}
		})
	})
}


